package com.hjl.controller;

import com.hjl.mapper.EmpMapper;
import com.hjl.pojo.Emp;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ServivE
 * @version 0.1
 * @className EmpController
 * @description
 * @date 2024/8/15 21:18
 * @since jdk17
 */
@Controller
public class FmController {
    @RequestMapping("toIndex")
    public String getIndex(Model model) {
        Emp emp = new Emp(10078, "null", 1.33333,"ns", new Date());
        model.addAttribute("emp", emp);//model存request域
        return "index";
    }

    @RequestMapping("showList")
    public String getSession(Model model) {
        Emp emp1 = new Emp(1001, "z3", 1.33333, "ns",new Date());
        Emp emp2 = new Emp(1002, "l4", 1.33333, "ns",new Date());
        Emp emp3 = new Emp(1003, "w5", 1.33333, "ns",new Date());
        List<Emp> list = new ArrayList<>();
        list.add(emp1);
        list.add(emp2);
        list.add(emp3);
        model.addAttribute("empList", list);
        return "list";
    }

    @RequestMapping("showEmp")
    public String getSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Emp emp = new Emp(10078, "null", 1.33333, "ns",new Date());
        session.setAttribute("emp", emp);
        return "emp";
    }
}
